options ls = 100 ps = 80 probsig=2;

data fuzzy1;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/a/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data fuzzy2;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/b/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data fuzzy3;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/c/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data fuzzy4;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/d/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data fuzzy5;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/e/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data fuzzy6;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/f/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data fuzzy7;  informat code $25.;informat bcode $20.;
   infile 'g:/data/scAT.5/g/AAT5.dat' delimiter='09'x;
   input date    time  $  build  sub   code    $   block   trial  lat     resp  $  corr  trialitm    bcode $;
data temp; set fuzzy1 fuzzy2 fuzzy3 fuzzy4 fuzzy5 fuzzy6 fuzzy7;

if block in (1,2,3,4) then delete;
if trial < 19 then delete;
if bcode = 'bcode' then delete;
/* If corr = 0 then delete; */

if code in ( 'good_false500', 'bad_false500', 'blackback_false500', 'whiteback_false500',
             'black_false600', 'white_false600', 'good_false600', 'bad_false600',
             'blackback_false600', 'whiteback_false600','male_false500', 'male_false600',
             'blackfemback_false500', 'blackfemback_false600', 'blackmaleback_false500',
             'blackmaleback_false600', 'female_false500', 'female_false600')
then item = 0;else item = 1;

if corr = 0 and item = 0 then do;response = 'corrrej'; err=0;end;
if corr = 0 and item = 1 then do;response = 'miss'; err=1;end;
if corr = 1 and item = 0 then do;response = 'falsalr'; err=1;end;
if corr = 1 and item = 1 then do;response = 'hit'; err=0;end;
if sub < 59 then delete;

/*proc means; class code; var lat;run;
proc means n mean std min; class bcode; var err; run;
proc means n mean std min; class sub bcode; var err; run;
proc means n mean std; class sub bcode; var err; run; */

proc sort;by sub bcode response; run;
proc means noprint data=temp n;
  by sub bcode response;var lat;
  output out=means  mean=speed; run;
proc transpose data=means prefix=speed name=name out=spdmeans;
  by sub bcode response;run;
proc sort; by name; run;
data prac;  set spdmeans; if name ^= '_FREQ_' then delete;
   if response = 'corrrej' then do;
      if speed1 = 30 then do; response = 'falsalr'; speed1 = 0.35; end;
      else delete; end;
   if response = 'miss' then do;
      if speed1 = 30 then do; response = 'hit'; speed1 = 0.35; end;
      else delete; end;
   if response = 'hit' and speed1 = 30 then speed1 = 29.65;
   if response = 'falsalr' and speed1 = 30 then speed1 = 29.65;
proc sort; by sub;
proc transpose data=prac prefix=freq name=name out=freq;
  by sub; run;
proc sort; by name; run;
data prac; set freq;
   Fblbd50 = probit(freq1/30); Hblbd50 = probit(freq2/30);
   Fblbd60 = probit(freq3/30); Hblbd60 = probit(freq4/30);
   Fbfbd50 = probit(freq5/30); Hbfbd50 = probit(freq6/30);
   Fbfbd60 = probit(freq7/30); Hbfbd60 = probit(freq8/30);
   Fbfgd50 = probit(freq9/30); Hbfgd50 = probit(freq10/30);
   Fbfgd60 = probit(freq11/30); Hbfgd60 = probit(freq12/30);
   Fblgd50 = probit(freq13/30); Hblgd50 = probit(freq14/30);
   Fblgd60 = probit(freq15/30); Hblgd60 = probit(freq16/30);
   Fbmbd50 = probit(freq17/30); Hbmbd50 = probit(freq18/30);
   Fbmbd60 = probit(freq19/30); Hbmbd60 = probit(freq20/30);
   Fbmgd50 = probit(freq21/30); Hbmgd50 = probit(freq22/30);
   Fbmgd60 = probit(freq23/30); Hbmgd60 = probit(freq24/30);
   Ffmbd50 = probit(freq25/30); Hfmbd50 = probit(freq26/30);
   Ffmbd60 = probit(freq27/30); Hfmbd60 = probit(freq28/30);
   Ffmgd50 = probit(freq29/30); Hfmgd50 = probit(freq30/30);
   Ffmgd60 = probit(freq31/30); Hfmgd60 = probit(freq32/30);
   Fmlbd50 = probit(freq33/30); Hmlbd50 = probit(freq34/30);
   Fmlbd60 = probit(freq35/30); Hmlbd60 = probit(freq36/30);
   Fmlgd50 = probit(freq37/30); Hmlgd50 = probit(freq38/30);
   Fmlgd60 = probit(freq39/30); Hmlgd60 = probit(freq40/30);
   Fwhbd50 = probit(freq41/30); Hwhbd50 = probit(freq42/30);
   Fwhbd60 = probit(freq43/30); Hwhbd60 = probit(freq44/30);
   Fwhgd50 = probit(freq45/30); Hwhgd50 = probit(freq46/30);
   Fwhgd60 = probit(freq47/30); Hwhgd60 = probit(freq48/30);

   Dblbd50 = Hblbd50 - Fblbd50; Dblgd50 = Hblgd50 - Fblgd50;
   Dblbd60 = Hblbd60 - Fblbd60; Dblgd60 = Hblgd60 - Fblgd60;
   Dbfbd50 = Hbfbd50 - Fbfbd50; Dbfgd50 = Hbfgd50 - Fbfgd50;
   Dbfbd60 = Hbfbd60 - Fbfbd60; Dbfgd60 = Hbfgd60 - Fbfgd60;
   Dbmbd50 = Hbmbd50 - Fbmbd50; Dbmgd50 = Hbmgd50 - Fbmgd50;
   Dbmbd60 = Hbmbd60 - Fbmbd60; Dbmgd60 = Hbmgd60 - Fbmgd60;
   Dwhbd50 = Hwhbd50 - Fwhbd50; Dwhgd50 = Hwhgd50 - Fwhgd50;
   Dwhbd60 = Hwhbd60 - Fwhbd60; Dwhgd60 = Hwhgd60 - Fwhgd60;
   Dfmbd50 = Hfmbd50 - Ffmbd50; Dfmgd50 = Hfmgd50 - Ffmgd50;
   Dfmbd60 = Hfmbd60 - Ffmbd60; Dfmgd60 = Hfmgd60 - Ffmgd60;
   Dmlbd50 = Hmlbd50 - Fmlbd50; Dmlgd50 = Hmlgd50 - Fmlgd50;
   Dmlbd60 = Hmlbd60 - Fmlbd60; Dmlgd60 = Hmlgd60 - Fmlgd60;

   Fblbdal = probit((freq1+freq3)/60);   Hblbdal = probit((freq2+freq4)/60);
   Fbfbdal = probit((freq5+freq7)/60);   Hbfbdal = probit((freq6+freq8)/60);
   Fbfgdal = probit((freq9+freq11)/60);  Hbfgdal = probit((freq10+freq12)/60);
   Fblgdal = probit((freq13+freq15)/60); Hblgdal = probit((freq14+freq16)/60);
   Fbmbdal = probit((freq17+freq19)/60); Hbmbdal = probit((freq18+freq20)/60);
   Fbmgdal = probit((freq21+freq23)/60); Hbmgdal = probit((freq22+freq24)/60);
   Ffmbdal = probit((freq25+freq27)/60); Hfmbdal = probit((freq26+freq28)/60);
   Ffmgdal = probit((freq29+freq31)/60); Hfmgdal = probit((freq30+freq32)/60);
   Fmlbdal = probit((freq33+freq35)/60); Hmlbdal = probit((freq34+freq36)/60);
   Fmlgdal = probit((freq37+freq39)/60); Hmlgdal = probit((freq38+freq40)/60);
   Fwhbdal = probit((freq41+freq43)/60); Hwhbdal = probit((freq42+freq44)/60);
   Fwhgdal = probit((freq45+freq47)/60); Hwhgdal = probit((freq46+freq48)/60);
   Dblbdal = Hblbdal - Fblbdal; Dblgdal = Hblgdal - Fblgdal;
   Dbfbdal = Hbfbdal - Fbfbdal; Dbfgdal = Hbfgdal - Fbfgdal;
   Dbmbdal = Hbmbdal - Fbmbdal; Dbmgdal = Hbmgdal - Fbmgdal;
   Dwhbdal = Hwhbdal - Fwhbdal; Dwhgdal = Hwhgdal - Fwhgdal;
   Dfmbdal = Hfmbdal - Ffmbdal; Dfmgdal = Hfmgdal - Ffmgdal;
   Dmlbdal = Hmlbdal - Fmlbdal; Dmlgdal = Hmlgdal - Fmlgdal;

   if mod(sub,2) = 1 then order = 1; else order = 0;
   drop freq1-freq48;

proc sort data=prac; by sub; run;
data explicit;
  informat major $25.; informat ethnicit $25.;
  infile 'g:/data/scAT.5/AAT.5.explicit.txt' delimiter='09'x;
  input sub Awhite Ablack Amale Afemale Aasian Ahispanc Awmale Abmale Awfml Abfml Awhtblk
        male1-male10 black1-black10 cond year major $ age sex $ ethnicit $ race bornUS UShwlng
        Engfirst Enghwlng glasses handed $ sleep alert computer;

if mod(sub,4) in (1,2) then explicit = 1; else explicit = 2;
if race in (2,4,5) then race = 2;

if cond = 1 then do;
 Mm1 = male1; Mm2 = male2; Mm3 = male3; Mm4 = male4; Mm5 = male5;
 Mm6 = male6; Mm7 = male7; Mm8 = male8; Mm9 = male9; Mm10 = male10;
 Mb1 = black1; Mb2 = black2; Mb3 = black3; Mb4 = black4; Mb5 = black5;
 Mb6 = black6; Mb7 = black7; Mb8 = black8; Mb9 = black9; Mb10 = black10;end;
else do;
 Mm1 = male10; Mm2 = male9; Mm3 = male8; Mm4 = male7; Mm5 = male6;
 Mm6 = male5; Mm7 = male4; Mm8 = male3; Mm9 = male2; Mm10 = male1;
 Mb1 = black10; Mb2 = black9; Mb3 = black8; Mb4 = black7; Mb5 = black6;
 Mb6 = black5; Mb7 = black4; Mb8 = black3; Mb9 = black2; Mb10 = black1;end;
drop male1-male10 black1-black10;

proc sort data=explicit;by sub;run;
data prac;merge prac explicit;by sub;run;

data iat; infile 'g:/data/scat.5/iat.results.aat.5.txt' delimiter='09'x;
     input sub blackbad blackgd malebad malegd;
     raceIAT = blackbad - blackgd;genIAT = malebad - malegd;
proc sort data=IAT;by sub;run;
data prac;merge prac iat;by sub;run;

data prac;set prac;
  if sub in (64,78,83) then delete;
  if sub < 52 then delete;
  if sub = 63 then sex = 'f';
  recogn = 0;if sub in (83,85,95,104) then recogn = 2;else if sub in (80,88,89,93,100) then recogn = 1;
  if recogn > 0 then recogn = 1;
  Dblack = Dblgdal - Dblbdal;Dblkfml = Dbfgdal - Dbfbdal;Dblkml = Dbmgdal - Dbmbdal;
  Dwhite = Dwhgdal - Dwhbdal;Dfemale = Dfmgdal - Dfmbdal;Dmale = Dmlgdal - Dmlbdal;
  Drace = Dwhite - Dblack;Dgender = Dmale - Dfemale;
  Agender = Amale - Afemale; Arace = Awhite - Ablack;Argen = Abmale - Abfml;
  INTinex = mb1*mb2;
  if mb1 > 7 then INTmotiv = 'high'; else if mb1 < 8 then INTmotiv = 'low';
  if mb2 > 5 then EXTmotiv = 'high'; else if mb2 < 6 then EXTmotiv = 'low';

proc corr; var Dblack Dwhite Dfemale Dmale;run;

/*proc print; var sub Dblbd50 Dblgd50 Dblbd60 Dblgd60
   Dbfbd50 Dbfgd50 Dbfbd60 Dbfgd60 Dbmbd50 Dbmgd50
   Dbmbd60 Dbmgd60 Dwhbd50 Dwhgd50 Dwhbd60 Dwhgd60
   Dfmbd50 Dfmgd50 Dfmbd60 Dfmgd60 Dmlbd50 Dmlgd50
   Dmlbd60 Dmlgd60; run;*/

/*proc means; var Dblbdal Dblgdal Dbfbdal Dbfgdal Dbmbdal Dbmgdal
                Dwhbdal Dwhgdal Dfmbdal Dfmgdal Dmlbdal Dmlgdal;
proc means; class sex; var Dblbdal Dblgdal Dbfbdal Dbfgdal Dbmbdal Dbmgdal
                Dwhbdal Dwhgdal Dfmbdal Dfmgdal Dmlbdal Dmlgdal;run;
proc glm; model Dblbdal Dblgdal Dwhbdal Dwhgdal = /nouni; repeated race 2, AAT 2; run;
proc glm; model Dfmbdal Dfmgdal Dmlbdal Dmlgdal = /nouni; repeated gender 2, AAT 2; run;
proc glm; model Dbfbdal Dbfgdal Dbmbdal Dbmgdal = /nouni; repeated gender 2, AAT 2; run;

proc glm; model Dblbdal Dblgdal = /nouni; repeated AAT 2; run;
proc glm; model Dwhbdal Dwhgdal = /nouni; repeated AAT 2; run;
proc glm; model Dfmbdal Dfmgdal = /nouni; repeated AAT 2; run;
proc glm; model Dmlbdal Dmlgdal = /nouni; repeated AAT 2; run;
proc glm; model Dbfbdal Dbfgdal = /nouni; repeated AAT 2; run;
proc glm; model Dbmbdal Dbmgdal = /nouni; repeated AAT 2; run;*/

/*Gender
proc glm; class sex;model Dblbdal Dblgdal Dwhbdal Dwhgdal = sex /nouni; repeated race 2, AAT 2; run;
proc glm; class sex;model Dfmbdal Dfmgdal Dmlbdal Dmlgdal = sex /nouni; repeated gender 2, AAT 2; run;
proc glm; class sex;model Dbfbdal Dbfgdal Dbmbdal Dbmgdal = sex /nouni; repeated gender 2, AAT 2; run;

proc glm; class sex;model Dblbdal Dblgdal = sex /nouni; repeated AAT 2; run;
proc glm; class sex;model Dwhbdal Dwhgdal = sex /nouni; repeated AAT 2; run;
proc glm; class sex;model Dfmbdal Dfmgdal = sex /nouni; repeated AAT 2; run;
proc glm; class sex;model Dmlbdal Dmlgdal = sex /nouni; repeated AAT 2; run;
proc glm; class sex;model Dbfbdal Dbfgdal = sex /nouni; repeated AAT 2; run;
proc glm; class sex;model Dbmbdal Dbmgdal = sex /nouni; repeated AAT 2; run;

proc glm; model Dfmbdal Dfmgdal = /nouni; repeated AAT 2; where sex = 'm';run;
proc glm; model Dmlbdal Dmlgdal = /nouni; repeated AAT 2; where sex = 'm';run;*/

/*proc glm; model Dfmbdal Dfmgdal =  /nouni; where sex = 'f';repeated AAT 2; run;
proc glm; model Dmlbdal Dmlgdal =  /nouni; where sex = 'f';repeated AAT 2; run;
proc glm; model Dfmbdal Dfmgdal =  /nouni; where sex = 'm';repeated AAT 2; run;
proc glm; model Dmlbdal Dmlgdal =  /nouni; where sex = 'm';repeated AAT 2; run;*/

proc glm; class sex; model Dfmbdal Dfmgdal = sex; repeated AAT 2;run;
/*proc means; var Dblbd50 Dblgd50 Dblbd60 Dblgd60
   Dbfbd50 Dbfgd50 Dbfbd60 Dbfgd60 Dbmbd50 Dbmgd50
   Dbmbd60 Dbmgd60 Dwhbd50 Dwhgd50 Dwhbd60 Dwhgd60
   Dfmbd50 Dfmgd50 Dfmbd60 Dfmgd60 Dmlbd50 Dmlgd50
   Dmlbd60 Dmlgd60; run;
proc means; class sex; var Dblbd50 Dblgd50 Dblbd60 Dblgd60
   Dbfbd50 Dbfgd50 Dbfbd60 Dbfgd60 Dbmbd50 Dbmgd50
   Dbmbd60 Dbmgd60 Dwhbd50 Dwhgd50 Dwhbd60 Dwhgd60
   Dfmbd50 Dfmgd50 Dfmbd60 Dfmgd60 Dmlbd50 Dmlgd50
   Dmlbd60 Dmlgd60; run;

proc glm; model Dblbd50 Dblgd50 = /nouni;repeated AAT 2;run;
proc glm; model Dblbd60 Dblgd60 = /nouni;repeated AAT 2;run;
proc glm; model Dbmbd50 Dbmgd50 = /nouni;repeated AAT 2;run;
proc glm; model Dbmbd60 Dbmgd60 = /nouni;repeated AAT 2;run;
proc glm; model Dbfbd50 Dbfgd50 = /nouni;repeated AAT 2;run;
proc glm; model Dbfbd60 Dbfgd60 = /nouni;repeated AAT 2;run;
proc glm; model Dwhbd50 Dwhgd50 = /nouni;repeated AAT 2;run;
proc glm; model Dwhbd60 Dwhgd60 = /nouni;repeated AAT 2;run;
proc glm; model Dmlbd50 Dmlgd50 = /nouni;repeated AAT 2;run;
proc glm; model Dmlbd60 Dmlgd60 = /nouni;repeated AAT 2;run;
proc glm; model Dfmbd50 Dfmgd50 = /nouni;repeated AAT 2;run;
proc glm; model Dfmbd60 Dfmgd60 = /nouni;repeated AAT 2;run;

proc corr; var raceIAT genIAT Drace Dgender Arace Agender;run;
proc corr; var raceIAT genIAT blackbad blackgd malebad malegd;
           with Dblbdal Dblgdal Dbfbdal Dbfgdal Dbmbdal Dbmgdal
                Dwhbdal Dwhgdal Dfmbdal Dfmgdal Dmlbdal Dmlgdal;run;
proc corr; var raceIAT genIAT blackbad blackgd malebad malegd;
           with Arace Agender Awhite Ablack Abmale Abfml Awhtblk Amale Afemale;run;

proc means; var Awhite Ablack Amale Afemale Aasian Ahispanc Awmale Abmale Awfml Abfml Awhtblk;run;
proc means; class explicit; var Awhite Ablack Amale Afemale Aasian Ahispanc Awmale Abmale Awfml Abfml Awhtblk;run;
proc means; var mm1-mm10 mb1-mb10;run;
proc means; class explicit; var Awhite Ablack mm1-mm10 mb1-mb10;run;
proc corr; var mm1-mm10;run;
proc corr; var mb1-mb10;run;
proc corr; var Awhite Ablack Abmale Abfml Awhtblk; with mb1-mb10;run;

proc corr; var Dblack Dwhite Dblkml Dblkfml Dmale Dfemale; run;
proc corr; var Dblack Dwhite Dblkml Dblkfml Dmale Dfemale;
     with Awhite Ablack Abmale Abfml Awhtblk; run;
proc corr; var Dblack Dwhite Dblkml Dblkfml Dmale Dfemale;
     with mb1-mb10; run;
proc corr; var Dblack Dwhite Dblkml Dblkfml Dmale Dfemale;
     with mm1-mm10; run; 
*/
/*
proc print; var Awhite Ablack mb1 mb2 blackbad blackgd raceIAT Dblack Dwhite; run;
proc reg; model raceIAT = mb1 mb2 INTinex /stb; run;
proc reg; model Dblack = mb1 mb2 INTinex /stb; run;
proc reg; model Ablack = mb1 mb2 INTinex /stb; run;

proc univariate; var mb1 mb2;run;
proc means n mean stdev; class INTmotiv EXTmotiv; var raceIAT Dblack Ablack;run;
proc means; var mb1-mb10 mm1-mm10; run;*/


/*proc means; var Awhite Ablack Amale Afemale Abmale Abfml; run;
proc means; class sex; var Awhite Ablack Amale Afemale Abmale Abfml; run;

proc glm; model Ablack Awhite = /nouni; repeated race 2; run;
proc glm; model Afemale Amale = /nouni; repeated gender 2; run;
proc glm; model Abfml Abmale = /nouni; repeated gender 2; run;

proc glm; class sex; model Ablack Awhite = sex /nouni; repeated race 2; run;
proc glm; class sex; model Afemale Amale = sex /nouni; repeated gender 2; run;
proc glm; class sex; model Abfml Abmale = sex /nouni; repeated gender 2; run;

proc means; var raceIAT genIAT; run;
proc means; class sex; var raceIAT genIAT; run;

proc glm; class sex; model raceIAT = sex; run;
proc glm; class sex; model genIAT = sex; run;

proc means; var blackbad blackgd malebad malegd; run;
proc means; class sex; var blackbad blackgd malebad malegd; run;

proc glm; model blackbad blackgd = /nouni; repeated IAT 2;run;
proc glm; model malebad malegd = /nouni; repeated IAT 2;run;*/
/*
proc glm; class sex; model Ablack = sex;run;
proc glm; class sex; model Awhite = sex;run;
proc glm; class sex; model Amale = sex;run;
proc glm; class sex; model Afemale = sex;run;
proc glm; class sex; model Abmale = sex;run;
proc glm; class sex; model Abfml = sex;run;
proc glm; model Ablack Awhite = ;repeated race 2;run;
proc glm; model Amale Afemale = ;repeated gender 2;run;
proc glm; model Abmale Abfml = ;repeated rgen 2;run;
*/
proc corr; var Ablack Awhite Arace Dblack Dwhite raceIAT;run;
proc corr; var Afemale Amale Agender Dfemale Dmale genIAT ;run;
proc corr; var Abfml Abmale Dblkfml Dblkml;run;

proc corr; var Arace raceIAT Drace;run;
proc corr; var Agender genIAT Dgender;run;